<?php
class c_video extends DtDatabase
{
	public $id;
	public $channelId;
	public $filePath;
	public $fileSize;
	public $title;
	public $dtTime;
	public $tags;
	public $description;
	public $picture;
	public $counts;
	public $cguid;
	public $ordering;
	public $sign;

	public $primary_key='id';

	protected $table_name;
	private $im_virgin=false;

	public function __construct()
	{
		$this->table_name = TB_PREFIX.'video';
		$this->DtDatabase();		
}
	public function get_request($request=array())
	{
		if(!empty($request)){
		if($request['id'])$this->id=$request['id'];
		if($request['channelId'])$this->channelId=$request['channelId'];
		if($request['filePath'])$this->filePath=$request['filePath'];
		if($request['fileSize'])$this->fileSize=$request['fileSize'];
		if($request['title'])$this->title=$request['title'];
		if($request['dtTime'])$this->dtTime=$request['dtTime'];
		if($request['tags'])$this->tags=$request['tags'];
		if($request['description'])$this->description=$request['description'];
		if($request['picture'])$this->picture=$request['picture'];
		if($request['counts'])$this->counts=$request['counts'];
		if($request['cguid'])$this->cguid=$request['cguid'];
		if($request['ordering'])$this->ordering=$request['ordering'];
		if($request['sign'])$this->sign=$request['sign'];
		}
		}

	public function addnew($request=array())
	{
		$this->im_virgin =true;		if(!empty($request)){
		$this->get_request($request);
		}
		}

	public function save()
	{
		if($this->im_virgin){
		eval("\$this->$this->primary_key=NULL;");
		$sql="INSERT INTO `$this->table_name` (";
		$sql.=isset($this->id)?"id,":'';
		$sql.=isset($this->channelId)?"channelId,":'';
		$sql.=isset($this->filePath)?"filePath,":'';
		$sql.=isset($this->fileSize)?"fileSize,":'';
		$sql.=isset($this->title)?"title,":'';
		$sql.=isset($this->dtTime)?"dtTime,":'';
		$sql.=isset($this->tags)?"tags,":'';
		$sql.=isset($this->description)?"description,":'';
		$sql.=isset($this->picture)?"picture,":'';
		$sql.=isset($this->counts)?"counts,":'';
		$sql.=isset($this->cguid)?"cguid,":'';
		$sql.=isset($this->ordering)?"ordering,":'';
		$sql.=isset($this->sign)?"sign,":'';
if(substr($sql,strlen($str)-1,1)==',')$sql=substr($sql,0,strlen($str)-1);		$sql.=")VALUES (";
		$sql.=isset($this->id)?$this->id.',':'';
		$sql.=isset($this->channelId)?$this->channelId.',':'';
		$sql.=isset($this->filePath)?"'$this->filePath',":'';
		$sql.=isset($this->fileSize)?"'$this->fileSize',":'';
		$sql.=isset($this->title)?"'$this->title',":'';
		$sql.=isset($this->dtTime)?"'$this->dtTime',":'';
		$sql.=isset($this->tags)?"'$this->tags',":'';
		$sql.=isset($this->description)?"'$this->description',":'';
		$sql.=isset($this->picture)?"'$this->picture',":'';
		$sql.=isset($this->counts)?$this->counts.',':'';
		$sql.=isset($this->cguid)?"'$this->cguid',":'';
		$sql.=isset($this->ordering)?$this->ordering.',':'';
		$sql.=isset($this->sign)?$this->sign.',':'';
if(substr($sql,strlen($str)-1,1)==',')$sql=substr($sql,0,strlen($str)-1);		$sql.=')';

		}
		else{

		eval('$pid=$this->'.$this->primary_key.';$this->'.$this->primary_key.'=NULL;');

		$sql.="UPDATE `$this->table_name` SET ";
		$sql.=isset($this->id)?"`id`=$this->id,":'';
		$sql.=isset($this->channelId)?"`channelId`=$this->channelId,":'';
		$sql.=isset($this->filePath)?"`filePath`='$this->filePath',":'';
		$sql.=isset($this->fileSize)?"`fileSize`='$this->fileSize',":'';
		$sql.=isset($this->title)?"`title`='$this->title',":'';
		$sql.=isset($this->dtTime)?"`dtTime`='$this->dtTime',":'';
		$sql.=isset($this->tags)?"`tags`='$this->tags',":'';
		$sql.=isset($this->description)?"`description`='$this->description',":'';
		$sql.=isset($this->picture)?"`picture`='$this->picture',":'';
		$sql.=isset($this->counts)?"`counts`=$this->counts,":'';
		$sql.=isset($this->cguid)?"`cguid`='$this->cguid',":'';
		$sql.=isset($this->ordering)?"`ordering`=$this->ordering,":'';
		$sql.=isset($this->sign)?"`sign`=$this->sign,":'';
if(substr($sql,strlen($str)-1,1)==',')$sql=substr($sql,0,strlen($str)-1);
		$sql.=" WHERE `$this->primary_key` ='$pid' LIMIT 1";
		}
		return $this->query($sql);
	}
}
?>